package com.netsmart.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexUtil {
	
	public static boolean validatePhone(String phoneNumber){
		boolean bl = false;
		if(phoneNumber!=null){
			String regex = "^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|198|199|(147))\\d{8}$";
			Pattern pat = Pattern.compile(regex);
			Matcher mat = pat.matcher(phoneNumber);
			bl = mat.matches();
		}
		return bl;
	}
	
	public static boolean validateEmail(String email){
		boolean bl = false;
		if(email!=null){
			String regex = "^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(.[a-zA-Z0-9-]+)*.[a-zA-Z0-9]{2,6}$";
			Pattern pat = Pattern.compile(regex);
			Matcher mat = pat.matcher(email);
			bl = mat.matches();
		}
		return bl;
	}
	//验证是否是前端传来的base64编码图片，是返回文件名（带后缀），不是返回0
	public static String validateBase(String baseImage){
		String resp = "0";
		if(baseImage!=null&&baseImage.split(",").length==2){
			String imageName = System.currentTimeMillis() + "";
			String[] str = baseImage.split(",");
			if (str[0].equalsIgnoreCase("data:image/gif;base64")) {
				resp = imageName += ".gif";
			}else if (str[0].equalsIgnoreCase("data:image/png;base64")) {
				resp = imageName += ".png";
			}else if (str[0].equalsIgnoreCase("data:image/jpeg;base64")) {
				resp = imageName += ".jpeg";
			}else if (str[0].equalsIgnoreCase("data:image/x-ico;base64")) {
				resp = imageName += ".ico";
			}
		}
		return resp;
	}
	
	/*public static void main(String[] args) {
		String phoneNumber = null;
		String email = "11212@qq.com";
		System.out.println(validateEmail(email));
		System.out.println(validatePhone(phoneNumber));
	}*/
	
	
}
